apiVersion: v1
kind: Secret
metadata:
    name: postgres-credentials
type: Opaque
data:
    postgres_user: cG9zdGdyZXM= #postgres
    postgres_password: cGFzc3dvcmQ= #password
    postgres_db_name: cG9zdGdyZXM= #postgres
    postgres_data: L3Zhci9saWIvcG9zdGdyZXNxbC9kYXRhL3BnZGF0YQ== # /var/lib/postgresql/data/pgdata
    jdbc_driver: b3JnLnBvc3RncmVzcWwuRHJpdmVy # org.postgresql.Driver
    jdbc_url: amRiYzpwb3N0Z3Jlc3FsOi8vcG9zdGdyZXMtc2VydmljZTo1NDMyL3Bvc3RncmVzP3VzZXI9cG9zdGdyZXMmcGFzc3dvcmQ9cGFzc3dvcmQ= # jdbc:postgresql://postgres-service:5432/postgres?user=postgres&password=password

---
apiVersion: v1
kind: Secret
metadata:
    name: obp-credentials
type: Opaque
data:
    # Kafa
    connector: a2Fma2FfdlNlcHQyMDE4 #kafka_vSept2018
    kafka_bootstrap_hosts: a2Fma2Etc3ZjOjkwOTM= #kafka-svc:9093
    kafka_partitions: MQ== #1
    kafka_client_id: b2JwYXBpLXNlcnZpY2U= #obpapi-service
    api_instance_id: b2JwYXBpLXNlcnZpY2U= #obpapi-service
    kafka_akka_timeout: Mw== #3
    remotedata_timeout: Mw== #3
    # Debug
    display_internal_errors: dHJ1ZQ== # true


---
apiVersion: v1
kind: Service
metadata:
    name: obpapi-service
spec:
    selector:
        app: obpapi
    ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 8080
    type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
    name: obp-deployment
    labels:
        app: obpapi
spec:
    replicas: 1
    selector:
        matchLabels:
            app: obpapi
    template:
        metadata:
            labels:
                app: obpapi
        spec:
            containers:
            - name: obpapi
              image: openbankproject/obpapi-kube # docker build -t obpapi-kube .
              resources:
                requests:
                  cpu: "1"
                  memory: "200M"
                limits:
                  cpu: "1"
                  memory: "400M"
              env:
                - name: OBP_DB_DRIVER
                  valueFrom: 
                    secretKeyRef: 
                     name: postgres-credentials
                     key: jdbc_driver
                - name: OBP_DB_URL
                  valueFrom: 
                    secretKeyRef: 
                     name: postgres-credentials
                     key: jdbc_url
                - name: OBP_CONNECTOR
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: connector
                - name: OBP_KAFKA_BOOTSTRAP_HOSTS
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: kafka_bootstrap_hosts
                - name: OBP_KAFKA_PARTITIONS
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: kafka_partitions
                - name: OBP_KAFKA_CLIENT_ID
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: kafka_client_id
                - name: OBP_API_INSTANCE_ID
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: api_instance_id
                - name: OBP_KAFKA_AKKA_TIMEOUT
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: kafka_akka_timeout
                - name: OBP_REMOTEDATA_TIMEOUT
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: remotedata_timeout
                - name: OBP_DISPLAY_INTERNAL_ERRORS
                  valueFrom:
                    secretKeyRef:
                      name: obp-credentials
                      key: display_internal_errors
              ports:
              - containerPort: 8080
                name: http

---
apiVersion: v1
kind: Service
metadata:
    name: postgres-service
spec:
    selector:
        app: postgres
    ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432

---
apiVersion: apps/v1
kind: Deployment
metadata:
    name: postgres
    labels:
        app: postgres
spec:
    replicas: 1
    selector:
        matchLabels:
            app: postgres
    template:
        metadata:
            labels:
                app: postgres
        spec:
            containers:
            - name: postgres
              image: postgres:11.1-alpine
              resources:
                requests:
                  cpu: "1"
                  memory: "200M"
                limits:
                  cpu: "1"
                  memory: "400M"
              env: 
                - name: POSTGRES_USER
                  valueFrom:
                    secretKeyRef:
                     name: postgres-credentials
                     key: postgres_user
                - name: POSTGRES_PASSWORD
                  valueFrom:
                    secretKeyRef: 
                     name: postgres-credentials
                     key: postgres_password
                - name: POSTGRES_DB
                  valueFrom:
                    secretKeyRef: 
                     name: postgres-credentials
                     key: postgres_db_name
                - name: PGDATA
                  valueFrom:
                    secretKeyRef: 
                     name: postgres-credentials
                     key: postgres_data
              volumeMounts:
              - name: postgres-volume
                mountPath: "/var/lib/postgresql/data"
              ports:
              - containerPort: 5432
            volumes:
                - name: postgres-volume
                  persistentVolumeClaim:
                    claimName: obp-postgres-volume-claim
